/**
 * 描述：这是leetcode上面的链表的类，并在其基础上进行了一定程度的修改
 *
 * @author WangB
 * @create 2018-10-20-15:56
 */

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
public class ListNode{
     int val;
     ListNode next;
     ListNode(int x) { val = x; }

    /**
     * 添加了一个构造函数，用来接收一个数组，并将其转换成以当前节点为头节点的链表
     * @param arr
     */
    public ListNode(int[] arr){
         if(arr.length == 0 || arr==null)
             throw new IllegalArgumentException ( "数组是空的" );

         this.val = arr[0];
         ListNode cur = this;
         for ( int i = 1 ; i < arr.length ; i++ ) {
             cur.next= new ListNode ( arr[i] );
             cur = cur.next;
         }


     }

     @Override
    public String toString(){
        StringBuilder res = new StringBuilder ();
        ListNode cur = this;
        while(cur!=null){
            res.append ( cur.val +"->");
            cur = cur.next;
        }
        res.append ( "NULL" );
        return res.toString ();
     }

     public static void main(String[] args){
        int[] arr = new int[]{1,4,2,2,43,453,43};
        ListNode head = new ListNode ( arr );
        System.out.println ( head );
     }
}
